import rclpy
from rclpy.node import Node
from arduinobot_msgs.srv import AddTwoints

class SimpleServiceClient(Node):
    def __init__(self):
        super().__init__('simple_service_client')
        self.cli = self.create_client(AddTwoints, 'add_tow_int')
        while not self.cli.wait_for_service(timeout_sec=1.0):
            self.get_logger().info('Service not available, waiting again...')
        self.req = AddTwoints.Request()
        self.req.a = 1
        self.req.b = 2
        self.future = self.cli.call_async(self.req)
        self.get_logger().info('Request sent: "%d + %d" ' % (self.req.a , self.req.b))
        self.future.add_done_callback(self.callback)
        
    def callback(self, future):
        try:
            response = future.result()
        except Exception as e:
            self.get_logger().info('Service call failed %r' % (e,))
        else:
            self.get_logger().info('Result of add_two_ints: %d' % (response.sum))

def main():
    rclpy.init()
    simple_service_client = SimpleServiceClient()
    rclpy.spin(simple_service_client)
    simple_service_client.destroy_node()
    rclpy.shutdown()

if __name__ == '__main__':
    main()